package com.zbb.order.api;

import com.zbb.base.model.PageParams;
import com.zbb.base.model.PageResult;
import com.zbb.base.model.Result;
import com.zbb.order.mapper.OrderSnapshotMapper;
import com.zbb.order.model.dto.OrderCount;
import com.zbb.order.model.dto.OrderSnapshotDto;
import com.zbb.order.model.dto.QueryOrderInitiateDto;
import com.zbb.order.model.po.OrderInitiate;
import com.zbb.order.model.po.OrderSnapshot;
import com.zbb.order.model.po.User;
import com.zbb.order.service.OrderInitiateService;
import com.zbb.order.service.OrderSnapshotService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "订单快照查询/编辑接口",tags = "订单快照/编辑接口")
@RestController
public class OrderSnapshotController {
    @Autowired
    OrderSnapshotService orderSnapshotService;

    @Autowired
    OrderSnapshotMapper orderSnapshotMapper;

    @ApiOperation("下单接口")
    @GetMapping("/placeOrder")
    public Result placeOrder(String userId,String initiateId,String detailId){
        Result result = orderSnapshotService.placeOrder(userId, initiateId, detailId);
        return result;
    }


    @ApiOperation("求助订单快照查询接口")
    @GetMapping("/getSnapshotList")
    public Result getSnapshotList(PageParams pageParams){
        PageResult<OrderSnapshotDto> snapshotDtos = orderSnapshotService.getSnapshotList(pageParams);
        return Result.ok(snapshotDtos);
    }

    @ApiOperation("帮助订单快照查询接口")
    @GetMapping("/getHelpSnapshotList")
    public Result getHelpSnapshotList(PageParams pageParams){
        PageResult<OrderSnapshotDto> snapshotDtos = orderSnapshotService.getHelpSnapshotList(pageParams);
        return Result.ok(snapshotDtos);
    }

    @ApiOperation("订单信息")
    @GetMapping("/getSnapshotInfo/{snapshotId}")
    public Result getSnapshotInfo(@PathVariable("snapshotId") String snapshotId){
        OrderSnapshot orderSnapshot = orderSnapshotMapper.selectById(snapshotId);
        return Result.ok(orderSnapshot);
    }

    @ApiOperation("订单信息")
    @PutMapping("/updateEvaluationStatus/{snapshotId}")
    public void updateEvaluationStatus(@PathVariable("snapshotId") String snapshotId, @RequestParam("evaluationStatus") Integer evaluationStatus){
        // 根据id更新指定资源的状态，并返回相应的结果
        OrderSnapshot orderSnapshot = orderSnapshotMapper.selectById(snapshotId);
        orderSnapshot.setEvaluationStatus(evaluationStatus);
        orderSnapshotMapper.updateById(orderSnapshot);
    }



    @ApiOperation("更新订单状态")
    @GetMapping("/updateSnapshotOrder")
    public Result updateSnapshotOrder(String snapshotId, int status){
        Result result = orderSnapshotService.updateSnapshotOrder(snapshotId,status);
        return result;
    }
    @ApiOperation("更新全部订单状态")
    @GetMapping("/updateUserStatus")
    public Result updateUserStatus(){
        Result result = orderSnapshotService.updateUserStatus();
        return result;
    }

    @ApiOperation("获取订单统计")
    @GetMapping("/getOrderMunCount")
    public Result getOrderMunCount(){
        OrderCount orderCount = orderSnapshotService.getOrderMunCount();
        return Result.ok(orderCount);
    }
    @ApiOperation("获取最近的一条订单数据")
    @GetMapping("/getUserSnapshotOne")
    public Result getUserSnapshotOne(){
        OrderSnapshot orderSnapshot = orderSnapshotService.getUserSnapshotOne();
        return Result.ok(orderSnapshot);
    }
}
